package com.burgeon.backend.SHOPBACKEND.service.Impl;

import com.burgeon.backend.SHOPBACKEND.entity.vip.Vip;
import com.burgeon.backend.SHOPBACKEND.entity.weixin.WeiXinUser;
import com.burgeon.backend.SHOPBACKEND.mappers.WxUserMapper;
import com.burgeon.backend.SHOPBACKEND.rest.weixin.FindVipByCardNo;
import com.burgeon.backend.SHOPBACKEND.service.VipService;
import com.burgeon.backend.SHOPBACKEND.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InWxUserServiceImpl implements WxUserService {

    @Autowired
    private WxUserMapper wxUserMapper;
    @Autowired
    private VipService vipService;


    @Override
    public Integer InWxUser(WeiXinUser weiXinUser) {
        return null;
    }

    //获取导购关联的微信用户列表
    @Override
    public ArrayList<Vip> getUserByOpenId(String daoId){
        System.err.println(daoId);
            if("null".equals(daoId)){
                throw new IllegalArgumentException("参数不正确");
            }
            List<String> openIds = wxUserMapper.getOpenId(daoId);
          //  ArrayList<WeiXinUser> weUsers = new ArrayList<>();
        ArrayList<Vip> wVips = new ArrayList<>();
            for (String openId : openIds) {
                Vip vip = vipService.findVipByOpenId(openId,daoId);
                wVips.add(vip);
            }
            return wVips;
    }

    //获取导购关联的微信用户列表
    @Override
    public Vip getUserInfoByOpenId(String cardNo){
        System.err.println(cardNo);
        if("null".equals(cardNo)){
            throw new IllegalArgumentException("参数不正确");
        }
        FindVipByCardNo findVipByCardNo = new FindVipByCardNo("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");

        Vip vip = null;
        try {
            vip = findVipByCardNo.getData(cardNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return vip;

    }
}
